//
//  TableCellOneForCollectionFive.m
//  喜马拉雅FM
//
//  Created by dllo on 16/1/28.
//  Copyright © 2016年 lanou.com. All rights reserved.
//

#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height


#import "UIImageView+WebCache.h"
#import "TableCellOneForCollectionFive.h"
#import "ModelForCollectionViewFive.h"

#import "ZhuBoInformationViewController.h"

@interface TableCellOneForCollectionFive ()

@property (nonatomic, retain) UILabel *labelForTitle;
@property (nonatomic, retain) UIImageView *picture;
@property (nonatomic, retain) UILabel *labelForNickname;
@property (nonatomic, retain) NSMutableArray *arrForSmallLogo;
@property (nonatomic, retain) NSMutableArray *arrForNickname;

@property (nonatomic, retain) NSMutableArray *arrForUid;

@end

@implementation TableCellOneForCollectionFive

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {

        self.arrForSmallLogo = [NSMutableArray array];
        self.arrForNickname = [NSMutableArray array];
        self.arrForUid = [NSMutableArray array];
        
        [self createSubViews];
        [self createTapGestureRecognizer];
    }
    return self;
}

- (void)createSubViews {

    UIImageView *image = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"biaoti"]];
    image.frame = CGRectMake(10, 15, 20, 20);
    [self.contentView addSubview:image];
    [image release];
    
    self.labelForTitle = [[UILabel alloc]initWithFrame:CGRectMake(30, 15, 150,20)];
    [self.contentView addSubview:self.labelForTitle];
    self.labelForTitle.text = @"热门";
    [self.labelForTitle release];
    
//    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//    button.frame = CGRectMake(WIDTH - 100, 15, 100, 20);
//    [button setTitle:@"更多 >" forState:UIControlStateNormal];
//    [button setTitleColor:[UIColor lightGrayColor] forState:UIControlStateNormal];
//    [self.contentView addSubview:button];
    
    for (int i = 0; i < 3; i++) {
        self.picture = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"1.jpg"]];
        self.picture.frame = CGRectMake(((WIDTH - 40)/3 + 10)*i + 10 , 50, (WIDTH - 40)/3, (WIDTH - 40)/3);
        self.picture.tag = 1 + i;
        [self.contentView addSubview:self.picture];
        self.picture.userInteractionEnabled = YES;
        [self.picture release];
        
        self.labelForNickname = [[UILabel alloc]initWithFrame:CGRectMake(((WIDTH - 40)/3 + 10)*i + 10, 50 + (WIDTH - 40)/3, (WIDTH - 40)/3, 30)];
        self.labelForNickname.text = @"NJ雨瞳";
        self.labelForNickname.textAlignment = NSTextAlignmentCenter;
        self.labelForNickname.tag = 10 + i;
        [self.contentView addSubview:self.labelForNickname];
        [self.labelForNickname release];
        
//        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
//        button.frame = CGRectMake(((WIDTH - 40)/3 + 10)*i + 20, 50 + (WIDTH - 40)/3 + 30, (WIDTH - 40)/3 - 10 , 30);
//        [self.contentView addSubview:button];
//        [button setBackgroundImage:[UIImage imageNamed:@"17000169"] forState:UIControlStateNormal];
////        [button setTitle:@"+ 关注" forState:UIControlStateNormal];
//        [button setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal];
//        button.layer.cornerRadius = 5;
//        button.layer.masksToBounds = YES;
//        [button.layer setBorderWidth:2];  // 设置边界的宽度
// 
//        [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
//        button.layer.borderColor = [UIColor orangeColor].CGColor;
    }
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(0,50 + (WIDTH - 40)/3 + 30, WIDTH,30);
    [self.contentView addSubview:button];
    [button setBackgroundImage:[UIImage imageNamed:@"100"] forState:UIControlStateNormal];
    //        [button setTitle:@"+ 关注" forState:UIControlStateNormal];
    [button setTitleShadowColor:[UIColor whiteColor] forState:UIControlStateNormal];
    button.layer.cornerRadius = 5;
    button.layer.masksToBounds = YES;
//    [button.layer setBorderWidth:2];  // 设置边界的宽度
    
    [button setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
//    button.layer.borderColor = [UIColor orangeColor].CGColor;
    
    
    
}


- (void)createTapGestureRecognizer {
    
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapAction:)];
    [[self.contentView viewWithTag:1] addGestureRecognizer:tap];
    
    UITapGestureRecognizer *tap1 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapAction:)];
    [[self.contentView viewWithTag:2] addGestureRecognizer:tap1];
    
    UITapGestureRecognizer *tap2 = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(handleTapAction:)];
    [[self.contentView viewWithTag:3] addGestureRecognizer:tap2];
    [tap2 release];
    [tap1 release];
    [tap release];
}

- (void)handleTapAction:(UITapGestureRecognizer *)tap {
    
    ZhuBoInformationViewController *zhuBo = [[ZhuBoInformationViewController alloc]init];
    // 根据tap在哪个视图上来判断传值.
    if (tap.view == [self.contentView viewWithTag:1]) {
        zhuBo.stringUid = self.arrForUid[0];
    }else if (tap.view == [self.contentView viewWithTag:2]){
        zhuBo.stringUid = self.arrForUid[1];
    }
    else {
        zhuBo.stringUid = self.arrForUid[2];
    }
    
    // 获取该视图层最下边的VC.
    id object = [self nextResponder];
    while (![object isKindOfClass:[UIViewController class]] &&
           object != nil) {
        object = [object nextResponder];
    }
    UIViewController *vc = (UIViewController*)object;
    [vc.navigationController pushViewController:zhuBo animated:NO];
}







- (void)passModelForCell:(ModelForCollectionViewFive *)model {

    self.labelForTitle.text = model.title;
    [self.arrForNickname removeAllObjects];
    [self.arrForSmallLogo removeAllObjects];
    [self.arrForUid removeAllObjects];
    
    for (NSDictionary *dic in model.arrForSmallLogo) {
        NSString *str = [dic objectForKey:@"smallLogo"];
        [self.arrForSmallLogo addObject:str];
        str = [dic objectForKey:@"nickname"];
        [self.arrForNickname addObject:str];
        
        str = [dic objectForKey:@"uid"];
        [self.arrForUid addObject:str];
    }

    for (int i = 0; i < 3; i ++) {
      UIImageView *pic = [self.contentView viewWithTag:(1 + i)];
        [pic sd_setImageWithURL:[NSURL URLWithString:self.arrForSmallLogo[i]]];
        
        UILabel *label = [self.contentView viewWithTag:(10 + i)];
        label.text = self.arrForNickname[i];
    }
}

- (void)awakeFromNib {

}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    
    [super setSelected:selected animated:animated];
}


@end
